package statesPattern;

public class NoQuarterState implements State{

    private final GumballMachine gumballMachine;

    /***
     * 我们通过构造函数得到糖果机的引用，然后将它记录在实例变量中
     * @param gumballMachine
     */
    public NoQuarterState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }

    //如果有人投了25分钱，我们就打印一条消息。说我们接受了25分钱，然后改变机器的状态到HasQuarterState
    @Override
    public void insertQuarter() {
        System.out.println("You inserted a quarter");
        gumballMachine.setState(gumballMachine.getHasQuarterState());
    }

    @Override
    public void ejectQuarter() {
        System.out.println("You haven't inserted a quarter");
    }

    @Override
    public void turnCrank() {
        System.out.println("You turned,but there's no quarter");
    }

    @Override
    public void dispense() {
        System.out.println("You need to pay first");
    }
}
